<?php
namespace Wx\Controller;
use Think\Controller;

class ExchangeOrderController extends CommonController{

    // 门店-兑换订单列表
    public function index(){
        $u_id = session('u_id');
        $exchange_order = M('exchange_order');
        $shop_store = M('shop_store');
        // 查询店主店铺的小区id
        $c_id = $shop_store->where("u_id = {$u_id}")->getField('c_id');
        // 订单状态
        $state = $_GET['state'];
        if($state!=''){
            $where = "eo.c_id = {$c_id} AND eo.state = {$state}";
        }else{
            $where = "eo.c_id = {$c_id}";
        }// end if
        $list = $exchange_order->table(C('DB_PREFIX')."exchange_order as eo")
                ->join(C('DB_PREFIX')."exchange_goods as eg ON eg.id=eo.g_id")
                ->field("eo.*,eg.title,eg.head_img,eg.unit,eg.u_num,eg.unit,eg.price as eg_price,eg.u_id as eg_u_id")
                ->where($where)
                ->order('eo.id desc')
                ->select();
        $this->assign('list',$list);
        $this->assign('state',$state);
        $this->display('order-dh');

    }//end fun

    // 门店-兑换订单详情
    public function info(){
        $id = intval(I('id'));
        $u_id = session('u_id');
        $exchange_order = M('exchange_order');
        $member = M('member');
        $shop_store = M('shop_store');
        // 订单信息
        $info = $exchange_order->table(C('DB_PREFIX')."exchange_order as eo")
            ->join(C('DB_PREFIX')."exchange_goods as eg ON eg.id=eo.g_id")
            ->field("eo.*,eg.title,eg.head_img,eg.unit,eg.u_num,eg.unit,eg.price as eg_price,eg.u_id as eg_u_id")
            ->where("eo.id = {$id}")
            ->find();
        // 订单取货人信息
        $m_info = $member->where('id='.$info['u_id'])->field('realname,mobile')->find();
        // 店主门店信息
        $store = $shop_store->where("u_id = {$u_id}")->field('storename,address')->find();

        $this->assign('info',$info);
        $this->assign('m_info',$m_info);
        $this->assign('store',$store);
        $this->display('orderdetail-dh');
    }//end fun


}//end class